/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servlets;
import java.util.regex.Matcher;  
import java.util.regex.Pattern;  

/**
 *
 * @author Don
 */
public class input_regex_checks {
    
    
    public boolean isValidEmailAddress(String emailAddress){  
         String  expression="^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov)|(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\.aero)|(\\.arpa)|(\\.coop)|(\\.int)|(\\.jobs)|(\\.museum)|(\\.name)|(\\.pro)|(\\.travel)|(\\.nato)|(\\..{2,3})|(\\..{2,3}\\..{2,3}))$";  
         CharSequence inputStr = emailAddress;  
         Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);  
         Matcher matcher = pattern.matcher(inputStr);   
         return matcher.matches();  
    }  
    
    public boolean lettersOnly(String letters) {
        return letters.matches("^[a-zA-Z]+$");
    }
    
    public boolean numbersOnly(String numbers){
        return numbers.matches("^[0-9]+$");
    }
    
    public boolean dateOnly(String date){
        return date.matches("(0[1-9]|[1-9]|[12][0-9]|3[01])[\\-/.]?(0[1-9]|1[012]|[1-9])[\\-/.]?(19|20)?\\d{2}");
       // return date.matches("(19|20)\\d{2}-(((0[13456789]|1[012])-([0-3][0-1]|[0-2][0-9]))|((02-([0-2][0-9]))))");
    }
    
    public boolean lettersNumbers (String letternumber)
    {
        return letternumber.matches("^[0-9a-zA-Z]+$");
    }
}
